package com.liang.rabbitmq.service.impl;

import com.liang.rabbitmq.pojo.OrderEntity;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import java.io.IOException;


@Service
@RabbitListener(queues = {"hello.q"})
public class RabbitServiceImpl {
    @RabbitHandler
    public void getMsg(Message message, OrderEntity orderEntity, Channel channel){
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        System.out.println("消费消息------------》orderEntity = " + orderEntity);
        try {
            //false 非批量签收
            channel.basicAck(deliveryTag,false);
        } catch (IOException e) {
            try {
                channel.basicNack(deliveryTag,false,true);
            } catch (IOException ioException) {
                ioException.printStackTrace();
            }
            e.printStackTrace();
        }
    }


}
